package genome;

public class GateFunctionSet extends FunctionSet{
	
	public int NUM_FUNCTIONS = 4;
	public int ARITY = 2;
	
	//basic numerical function set
	
	public String toString(){
		return "GateFunctionSet";
	}
	
	public double func(double[] c,int function){
		
		boolean c0 = (c[0]==0.0)? false : true;
		boolean c1 = (c[1]==0.0)? false : true;
		
		boolean c3;
		
		switch(function){
			case 0 :
				//AND
				c3 = c0&&c1;
			break;
			
			case 1 :
				//OR
				c3 = c0||c1;
			break;
				
			case 2 :
				//XOR
				c3 = c0^c1;
			break;
				
			case 3 :
				//NAND
				c3 = !(c0&&c1);
			break;
				
			default :
				c3 = false;
			break;
			
		}
		return c3 ? 1.0:0.0;
	}
	
	public String getfString(String[] s, int function){
		//All functions are at least biarity, so always evaluate these.
		
		String s0 = s[0];
		String s1 = s[1];
			
		switch(function){
			case 0 :
				//AND
				return "["+s0+"AND"+s1+"]";
			
			case 1 :
				//OR
				return "["+s0+"OR"+s1+"]";
				
			case 2 :
				//XOR
				return "["+s0+"XOR"+s1+"]";
				
			case 3 :
				//NAND
				return "["+s0+"NAND"+s1+"]";
				
			default :
				return "FALSE";
			
		}
	}
}
